package cn.js.sangu.unitStore;

import cn.js.sangu.unitStore.service.UtilsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@Slf4j
@SpringBootApplication
public class UnitStoreApplication {

    @Autowired
    private UtilsService utilsService;

    public static void main(String[] args) {
        SpringApplication.run(UnitStoreApplication.class, args);
        log.info("====> Spring Boot Main启动：项目根路径：【{}】 <====",System.getProperty("user.dir"));
    }

    @Bean
    public ApplicationRunner applicationRunner(){
        return args -> {
            long startTime = System.currentTimeMillis();
            log.info("====> {}线程：开始调用异步任务 <====",Thread.currentThread().getName());
            //调用异步
            utilsService.asyncTask();

            long end = System.currentTimeMillis();
            log.info("====> {}线程：调用异步任务结束，耗时{}毫秒",Thread.currentThread().getName(),end-startTime);
        };
    }

}
